//== 待办任务-列表页
let taskList = function () {
    /**
     * 初始化列表
     */
    let initTable = function () {
        let options = {
            url: ETool.getBaseUrl() + 'select/' + status,
            // 列配置
            columns: [
                {
                    field: 'processInstanceId',
                    title: '流水号',
                    sortField: 'art.proc_inst_id_'
                },
                {
                    field: 'businessTitle',
                    title: '工作内容',
                    sortField: 'arv_businessTitle.text_'
                },
                {
                    field: 'processDefinitionName',
                    title: '所属流程',
                    sortField: 'arp.name_'
                },
                {
                    field: 'name',
                    title: '当前步骤',
                    sortField: 'art.name_'
                },
                {
                    field: 'applyUser',
                    title: '发起人',
                    sortField: 'arv_applyUserId.text_'
                },
                {
                    field: 'createTime',
                    title: '发起时间',
                    sortable: 'asc',
                    sortField: 'art.create_time_'
                },
                {
                    field: 'Actions',
                    width: 120,
                    title: '操作',
                    sortable: false,
                    overflow: 'visible',
                    locked: {
                        right: 'md'
                    },
                    template: function (row, index, datatable) {
                        let _btn = '';
                        if (EUtil.isBlank(row.assignee)) {
                            _btn += '<a href="#" onclick="taskList.claimTask(\'' + row.id + '\')" class="' + ETool.ACTIONS_INFO + '" title="签收">\
                                <i class="la la-calendar-check-o"></i>\
                            </a>';
                        } else {
                            _btn += '<a href="#" onclick="EApp.openPage(\'办理：' + row.businessTitle + '\', \'' + ETool.getBaseUrl() + 'task/form/' + row.id + '\')" class="' + ETool.ACTIONS_INFO + '" title="办理">\
                                <i class="la la-edit"></i>\
                            </a>';
                        }
                        _btn += '\
                            <a href="#" onclick="EWorkFlow.openProcessProgress(\'' + row.executionId + '\',\'' + row.processInstanceId + '\')" class="' + ETool.ACTIONS_INFO + '" title="流程跟踪">\
                                <i class="la la-search"></i>\
                            </a>';

                        return _btn;
                    }
                }

            ]
        };
        taskList.dataTable = ETool.initDataTable(options);
    };

    /**
     * 签收任务
     *
     * @param taskId {string} 任务id
     */
    let claimTask = function (taskId) {
        EUtil.ajax({
            url: ETool.getBaseUrl() + 'claim/task/' + taskId,
            success: function () {
                ETool.successTip(commonTips.success, '任务已签收');
                taskList.dataTable.reload();
            }
        });
    };

    return {
        //== 初始化页面
        init: function () {
            ETool.setBaseUrl(basePath + '/auth/activiti/task/');
            initTable();
        },
        /**
         * 签收任务
         *
         * @param taskId {string} 任务id
         */
        claimTask: function (taskId) {
            claimTask(taskId);
        }
    };
}();
/**
 * 当前tab激活时是否需要重新加载数据
 *
 * @return {boolean} true/false
 */
ETab.needSubmitForm = function () {
    return true;
};
//== 初始化
$(document).ready(function () {
    taskList.init();
});